<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;

class CreateRoleTable extends Migration
{
    /**
     * run migrate
     * 运行迁移应用
     */
    public function up(){
        Schema::create('role', function(Blueprint $table){
            $table->engine = 'InnoDB';
            $table->charset = 'utf8mb4';
            $table->collation = 'utf8mb4_general_ci';

            $table->increments('id')->comment('主键');
            $table->string('name', 255)->nullable(false)->comment('角色名称');
            $table->tinyInteger('status')->unsigned()->nullable(true)->default(0)->comment('状态，0为禁用，1为启用，默认为0');
            $table->tinyInteger('is_administrator')->unsigned()->nullable(true)->default(0)->comment('超级管理员，0不是，1是，默认为0');
            $table->text('rule')->nullable(true)->comment('角色可控的菜单');
            $table->dateTime('updated_at')->nullable(true)->comment('修改日期');
            $table->dateTime('created_at')->nullable(true)->comment('创建日期');

            $table->unique('name', 'name');
        });
        DB::statement("ALTER TABLE `role` comment '权限表'");
    }

    /**
     * reset migrate
     * 运行回滚时应用
     */
    public function down(){
        Schema::dropIfExists('role');
    }
}